/**
 * Android FriendFeed Client
 * Copyright (C) 2010 E & B Labs
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.eblabs.androidfriendfeedclient;

import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author epplestun
 */
public class FriendfeedComment {
    /**
     * Cuerpo del comentario.
     */
    private String body;

    /**
     * Autor del comentario.
     */
    private String from;

    /**
     * Autor del comentario.
     */
    private String fromId;

    /**
     * Fecha del comentario.
     */
    private String date;

    /**
     * Identificador de comentario.
     */
    private String id;

    /**
     *
     * @param body
     */
    public void setBody(String body) {
        this.body = body;
    }

    /**
     *
     * @return
     */
    public String getBody() {
        return this.body;
    }

    /**
     *
     * @param from
     */
    public void setFrom(String from) {
        this.from = from;
    }

    /**
     *
     * @return
     */
    public String getFrom() {
        return this.from;
    }

    /**
     *
     * @param fromId
     */
    public void setFromId(String fromId) {
        this.fromId = fromId;
    }

    /**
     *
     * @return
     */
    public String getFromId() {
        return this.fromId;
    }

    /**
     *
     * @param fromId
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     *
     * @return
     */
    public String getId() {
        return this.id;
    }

    /**
     *
     * @param date
     */
    public void setDate(String date) {
        this.date = date;
    }

    /**
     *
     * @return
     */
    public String getDate() {
        return this.body;
    }

    /**
     * Constructor por defecto.
     */
    public FriendfeedComment() {
        super();
    }

    /**
     * Constructor basandose en un Entry JSON.
     * @param item Entry JSON.
     * @throws JSONException Excepción en caso de error.
     */
    public FriendfeedComment(JSONObject item) throws JSONException {
        this.setBody(
                item.getString("body").toString().replaceAll("\\<.*?>", ""));
        this.setFrom(
                item.getJSONObject("from").getString("name"));
        this.setFromId(
                item.getJSONObject("from").getString("id"));
        this.setDate(
                item.getString("date"));
        this.setId(
                item.getString("id"));
    }

    /**
     *
     * @param comments
     * @return
     * @throws JSONException
     */
    public static ArrayList<FriendfeedComment>
            commentsToArrayList(JSONArray comments) throws JSONException {
        ArrayList<FriendfeedComment> result = new ArrayList<FriendfeedComment>();

            for (int i = 0; i < comments.length(); i++) {
                FriendfeedComment ffComment = new FriendfeedComment(
                        comments.getJSONObject(i));
                result.add(ffComment);
            }

            return result;
    }
}